import React, { PureComponent } from "react";
import style from "./style.less";
import { forgetPassword } from "../../services/api/user";

class EmailTemp extends PureComponent {
  state = {};

  openEmail = () => {
    const { email } = this.props;
    window.open(`http://mail.${email.split("@")[1]}`);
    // window.location.href = `http://mail.${email.split("@")[1]}`;
  };

  reSendEmail = () => {
    const { email, captcha } = this.props;
    forgetPassword({
      email,
      captcha,
      method: "email",
      field: "email",
      value: email,
      return_type: "json"
    });
  };

  render() {
    const { email } = this.props;
    return (
      <div className={style.EmailTemp}>
        <div className={style.send}>邮件已发送，请注意查收！</div>
        <div className={style.mailContent}>
          我们已经确认您的身份，并给您的注册邮箱：<span>{email}</span>
          发送了设置新密码的邮件，请登录邮箱及时修改密码。
        </div>
        <div className={style.findsth} onClick={this.openEmail}>
          立即查收邮件
        </div>
        <div className={style.failed}>
          若您没有收到邮件请注意查看是否在垃圾箱，或者点击
          <span className={style.resend} onClick={this.reSendEmail}>
            重发
          </span>
        </div>
      </div>
    );
  }
}

export default EmailTemp;
